import prisma from '~~/lib/prisma'
import { Result } from '~~/lib/helper/result'
import Joi from 'joi'

export default defineEventHandler(async (event) => {
  const body = await readBody(event)
  const schema = Joi.object({ id: Joi.number().required() })
  try {
    await schema.validateAsync(body)
  } catch (error) {
    return Result.Error('参数错误！')
  }
  try {
    await prisma.notebook.delete({ where: { id: body.id } })
    return Result.Ok('删除文件集成功！')
  } catch (error) {
    return Result.Error('删除文集失败！')
  }
})
